Imports pixolut.BizBloxBuilderCore
Imports System.IO

Module Main
    Private project As New BBXProject

    Public Sub main()
        Console.WriteLine("BizBlox Builder (C)2003 - 2008 Pixolut Industries")
        Console.WriteLine("This tool will process BBX project files.")
        Dim args As String() = Environment.GetCommandLineArgs()
        If args.Length > 1 Then
            Dim quiet As Boolean = False
            Dim defProject As Boolean = False

            For i As Integer = 1 To args.Length - 1
                If args(i) = "-q" Then
                    quiet = True
                ElseIf (args(i) = "-h") Or (args(i) = "-help") Then
                    Console.WriteLine("BizBloxBuilderCMD [-q] filename.bbx")
                    Console.WriteLine("Use -q for silent processing")
                    End
                Else
                    If File.Exists(args(i)) Then DoLoad(args(i))
                End If
            Next
            PerformRender(quiet)
        End If
        Console.WriteLine("Completed")
    End Sub

    Private Sub PerformRender(ByVal quiet As Boolean)
        Try
            If Not quiet Then
                Console.WriteLine("Output folder: " & project.Destination)
                project.performRender(AddressOf quietStatus, AddressOf detail)
            Else
                project.performRender(AddressOf quietStatus, AddressOf quietDetail)
            End If
        Catch ex As Exception
            Console.WriteLine("Error occurred rendering: " & ex.ToString())
            End
        End Try
    End Sub

    Public Sub detail(ByVal msg As String)
        Console.WriteLine(msg)
    End Sub

    Public Sub quietDetail(ByVal msg As String)

    End Sub

    Public Sub quietStatus(ByVal current As Integer, ByVal max As Integer)

    End Sub

    Private Sub DoLoad(ByVal filename As String)
        Try
            project.Load(filename)
            Console.WriteLine("Load BBX Project: " & filename)

            If Not project.ErrorState = BBXProject.errState.OK Then
                Console.WriteLine("Error occurred opening the project file: " & project.ErrorMessage)
                End
            End If
        Catch ex As Exception
            Console.WriteLine("Error occurred opening the project file: " & ex.ToString())
            End
        End Try
    End Sub
End Module
